<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="6">
        <div class="form-item">
          <span class="title">客户电话</span>
          <el-input placeholder="请输入电话" v-model="param.withdrawalapplication.mobile"></el-input>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="form-item">
          <span class="title">创建日期</span>
          <el-date-picker
            v-model="createdateList"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :clearable="false"
          ></el-date-picker>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="form-item button-container">
          <el-button type="primary" @click="search" icon="el-icon-search">查询</el-button>
          <el-button type="primary" @click="resetSearchCotnet" icon="el-icon-refresh">重置</el-button>
        </div>
      </el-col>
    </el-row>
    <el-container>
      <el-tabs v-model="param.withdrawalapplication.appStatus" @tab-click="clicktab">
        <el-tab-pane label="未审批" name="0">
          <div class="table-body">
            <el-table :data="tableData" v-loading="isLoading" style="width: 100%">
              <el-table-column prop="customerIdName" label="客户昵称"></el-table-column>
              <el-table-column prop="mobile" label="客户电话"></el-table-column>
              <el-table-column prop="money" label="提现金额"></el-table-column>
              <el-table-column prop="createTime" label="申请时间"></el-table-column>
              <el-table-column prop="human" label="持卡人"></el-table-column>
              <el-table-column prop="cardId" label="卡号"></el-table-column>
              <el-table-column prop="cardBelongsBank" label="银行卡所属银行"></el-table-column>
              <el-table-column fixed="right" label="操作" width="150">
                <template slot-scope="scope">
                  <el-button
                    @click="handleToAgree(scope.row)"
                    type="primary"
                    size="small"
                    v-if="isPermissionsBtn('withdrawal_agree')"
                  >同意</el-button>
                  <el-button
                    @click="handleToNo(scope.row)"
                    type="danger"
                    size="small"
                    v-if="isPermissionsBtn('withdrawal_refuse')"
                  >拒绝</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="已审批" name="1">
          <div class="table-body">
            <el-table :data="tableData" v-loading="isLoading" style="width: 100%">
              <el-table-column prop="customerIdName" label="客户昵称"></el-table-column>
              <el-table-column prop="mobile" label="客户电话"></el-table-column>
              <el-table-column prop="money" label="提现金额"></el-table-column>
              <el-table-column prop="createTime" label="申请时间"></el-table-column>
              <el-table-column prop="human" label="持卡人"></el-table-column>
              <el-table-column prop="cardId" label="卡号"></el-table-column>
              <el-table-column prop="cardBelongsBank" label="银行卡所属银行"></el-table-column>
              <el-table-column prop="appOpinion" label="审批意见"></el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="已拒绝" name="2">
          <div class="table-body">
            <el-table :data="tableData" v-loading="isLoading" style="width: 100%">
              <el-table-column prop="customerIdName" label="客户昵称"></el-table-column>
              <el-table-column prop="mobile" label="客户电话"></el-table-column>
              <el-table-column prop="money" label="提现金额"></el-table-column>
              <el-table-column prop="createTime" label="申请时间"></el-table-column>
              <el-table-column prop="human" label="持卡人"></el-table-column>
              <el-table-column prop="cardId" label="卡号"></el-table-column>
              <el-table-column prop="cardBelongsBank" label="银行卡所属银行"></el-table-column>
              <el-table-column prop="appOpinion" label="审批意见"></el-table-column>
            </el-table>
          </div>
        </el-tab-pane>

        <div class="pagination">
          <el-pagination
            background
            @current-change="currentPageChange"
            layout="prev, pager, next"
            :page-size.sync="param.queryRequest.pageSize"
            :current-page.sync="param.queryRequest.pageNum"
            :total="totalCount"
          ></el-pagination>
        </div>
      </el-tabs>
    </el-container>
    <el-dialog title :visible.sync="DialogVisiblejj" width="40%">
      <el-form :model="form" :rules="rules" ref="formRef">
        <el-form-item label="审批意见" prop="explain" :label-width="formLabelWidth">
          <el-input type="textarea" :rows="3" placeholder="请填写" v-model="form.explain"></el-input>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth">
          <el-button plain @click="resetForm('formRef')">取消</el-button>
          <el-button type="primary" @click="submitForm('formRef')">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
export default {
  name: "",
  data() {
    return {
      formLabelWidth: "100px",
      form: {
        explain: ""
      },
      rules: {
        explain: [{ required: true, message: "请填写理由", trigger: "blur" }]
      },
      DialogVisiblejj: false,
      isLoading: false,
      createdateList: [],
      param: {
        withdrawalapplication: {
          appStatus: 0,
          mobile: "",
          startTime: "",
          endTime: ""
        },
        queryRequest: {
          pageNum: 1,
          pageSize: 10
        }
      },
      tableData: [],
      totalCount: 1,
      withdrawalId: "",
      withdrawalType: "",
      customerId: "",
      money: ""
    };
  },
  components: {},
  computed: {
    ...mapGetters(["isPermissionsBtn"])
  },
  beforeMount() {},
  mounted() {
    this.initData();
  },
  methods: {
    clicktab() {
      console.log(this.param.withdrawalapplication.appStatus);
      this.param.queryRequest.pageNum = 1;
      this.param.withdrawalapplication.mobile = "";
      this.param.withdrawalapplication.startTime = "";
      this.param.withdrawalapplication.endTime = "";
      this.createdateList = [];
      this.initData();
    },
    initData() {
      this.isLoading = true;
      if (this.createdateList.length > 0) {
        this.param.withdrawalapplication.startTime = this.createdateList[0];
        this.param.withdrawalapplication.endTime = this.createdateList[1];
      }
      this.$service.withdrawalapplicationWithdraw(this.param).then(res => {
        this.isLoading = false;
        if (res.code == "00000") {
          if (
            res.data.records.length == 0 &&
            this.param.queryRequest.pageNum != 1
          ) {
            this.param.queryRequest.pageNum -= 1;
            this.initData();
          }
          this.tableData = res.data.records || [];
          for (let i = 0; i < this.tableData.length; i++) {
            this.tableData[i].money = this.tableData[i].money / 100;
          }
          this.totalCount = res.data.total || 0;
        }
      });
    },
    handleToAgree(e) {
      this.withdrawalId = e.id;
      this.DialogVisiblejj = true;
      this.withdrawalType = "0";
    },
    handleToNo(e) {
      this.customerId = e.customerId;
      this.money = e.money*100;
      this.withdrawalId = e.id;
      this.DialogVisiblejj = true;
      this.withdrawalType = "1";
    },
    search() {
      this.param.queryRequest.pageNum = 1;
      this.initData();
    },
    resetSearchCotnet() {
      //重置搜索条件
      this.param.withdrawalapplication.mobile = "";
      this.param.withdrawalapplication.startTime = "";
      this.param.withdrawalapplication.endTime = "";
      this.createdateList = [];
    },
    currentPageChange(e) {
      this.param.queryRequest.pageNum = e;
      this.initData();
    },
    resetForm(formName) {
      this.DialogVisiblejj = false;
      // this.$emit("submit", false);
      this.$refs[formName].resetFields();
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        let message = this.form;
        if (valid) {
          var param = {};
          if (this.withdrawalType == "1") {
            param = {
              customerId: this.customerId,
              money: this.money,
              id: this.withdrawalId,
              userId: this.Global.user.userId,
              appOpinion: message.explain
            };
          } else {
            param = {
              id: this.withdrawalId,
              userId: this.Global.user.userId,
              appOpinion: message.explain
            };
          }

          if (this.withdrawalType == "0") {
            this.$service.withdrawalapplicationAgaree(param).then(res => {
              if (res.code == "00000") {
                this.$message({
                  message: "提交成功",
                  type: "success"
                });
                this.DialogVisiblejj = false;
                this.$refs[formName].resetFields();
                this.initData();
              } else {
                this.$message({
                  message: res.message,
                  type: "warning"
                });
              }
            });
          } else {
            this.$service.withdrawalapplicationRefuse(param).then(res => {
              if (res.code == "00000") {
                this.$message({
                  message: "提交成功",
                  type: "success"
                });
                this.DialogVisiblejj = false;
                this.$refs[formName].resetFields();
                this.initData();
              } else {
                this.$message({
                  message: res.message,
                  type: "warning"
                });
              }
            });
          }
        }
      });
    }
  },
  watch: {}
};
</script>
<style scoped>
</style>
